<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('角色列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								仓库名称：<input type="text" name="wareName"/>
							</li>
							<li>
								采购单编号：<input type="text" name="poPurIndent"/>
							</li>
							<li>
								状态：
								<select name="reStatus">
									<option value="0">请选择</option>
									<option value="1">未发货</option>
									<option value="2">已发货</option>
									<option value="3">已回款</option>
									<option value="4">取消订单</option>
									<option value="5">已退货</option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
		
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增出库
	            </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>

		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('storage:ware:edit')}]];
		var removeFlag = [[${@permission.hasPermi('storage:ware:remove')}]];
		var prefix = ctx + "storage/ck";


		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
				detailUrl: prefix + "/details/{id}",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        modalName: "仓库",
		        columns: [{
		            checkbox: true
		        },
		        {
		            title: '编号',
					formatter:function(value,row,index) {
		            	return $.table.serialNumber((index));
					}
		        },
				{
					field: 'ckId',
					visible:false
				},
		        {
		            field: 'mkOrderIndent',
		            title: '采购单编号',
		        },
		        {
		            field: 'money',
		            title: '金额',
		        },
				{
					field: 'wareName',
					title: '仓库名称',
				},
				{
					field: 'ckTime',
					title: '出库时间',
				},
				{
					field: 'sysCkUser',
					title: '出库人',
				},
				{
					field: 'reStatus',
					title: '状态',
					formatter: function (value) {
						if (value == 1) {
							return '未发货'
						}else if (value == 2){
							return '已发货'
						}else if (value == 3){
							return '已回款'
						}else if (value == 4){
							return '取消订单'
						}else {
							return "已退货"
						}
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	if (row.wareId != 0) {
							var action = [];
							action.push('<a class="btn btn-success btn-sm" style="margin-right: 5px" onclick="$.operate.detail(\''+ row.mkOrderIndent +'\')">查看详情</a>');
							if (row.reStatus == 1) {
								action.push('<a class="btn btn-primary btn-sm" href="#" style="margin-right: 5px" onclick="reEntryRe(2,'+ row.ckId +')">发货</a>');
								action.push('<a class="btn btn-warning btn-sm" href="#" style="margin-right: 5px" onclick="reEntryRe(4,'+ row.ckId +')">取消订单</a>');
							}else if (row.reStatus == 2){
								action.push('<a class="btn btn-warning btn-sm" href="#" style="margin-right: 5px" onclick="reEntryRe(4,'+ row.ckId +')">取消订单</a>');
								action.push('<a class="btn btn-primary btn-sm" href="#" onclick="reEntryRe(3,'+ row.ckId +')">确认回款</a>');
							}else if (row.reStatus == 3){
								action.push('<a class="btn btn-warning btn-sm" href="#" onclick="reEntryRe(4,'+ row.ckId +')">取消订单</a>');
							}else if (row.reStatus == 4){
								action.push('<a class="btn btn-primary btn-sm" href="#" onclick="reEntryRe(5,'+ row.ckId +')">确认已退货</a>');
							}
		                    return action.join('');
		            	} else {
		                    return "";
		                }
		            }
		        }]
		    };
		    $.table.init(options);
		});

		function reEntryRe(op,id) {
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "storage/ck/editStatus",
				data : {
					"ckId": id,
					"reStatus": op
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
	</script>
</body>
</html>